package com.bdth.bdthiss.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.bdth.bdthiss.entity.Seller;
import com.bdth.bdthiss.mapper.SellerMapper;
import com.bdth.bdthiss.service.SellerService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.bdth.bdthiss.vo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商家表 服务实现类
 * </p>
 *
 * @author LGP
 * @since 2019-08-21
 */
@Service
public class SellerServiceImpl extends ServiceImpl<SellerMapper, Seller> implements SellerService {
    @Autowired
    private SellerMapper sellerMapper;

    @Override
    public Page<Seller> listPages(Pagination pagination, String trueName, String mobile) {
        EntityWrapper<Seller> entityWrapper = new EntityWrapper<>();
        if(trueName!=null && !trueName.trim().equals(""))
            entityWrapper.like("true_name",trueName);
        if(mobile!=null)
            entityWrapper.like("mobile",mobile);
        if(pagination.getOrder()!=null) {
            if (pagination.getOrder().toLowerCase().equals("asc")){
                entityWrapper.orderBy(pagination.getSort(), true);
            }else{
                entityWrapper.orderBy(pagination.getSort(), false);
            }
        }
        Page<Seller> page = new Page<>(pagination.getPage()==null?1:pagination.getPage(),
                pagination.getRows()==null?20:pagination.getRows());

        List<Seller> items = sellerMapper.selectPage(page,entityWrapper);
        page.setRecords(items);
        return page;
    }
}
